package hotel.switchs.oversea.biz.service.impl;

import hotel.base.oversea.utils.DateUtil;
import hotel.base.oversea.utils.Result;
import hotel.switchs.oversea.api.entity.order.SwitchOrderListNotify;
import hotel.switchs.oversea.biz.mapper.SwitchOrderListNotifyMapper;
import hotel.switchs.oversea.biz.service.SwitchOrderListNotifyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 返回订单信息
 *
 * @author HuangT
 * @date 2020/7/7 20:43
 */
@Slf4j
@Service
public class SwitchOrderListNotifyServiceImpl implements SwitchOrderListNotifyService {
    @Autowired
    private SwitchOrderListNotifyMapper switchOrderListNotifyMapper;
    /**
     * 返回一条未创建子酒店的母酒店id
     * 条件 is_create_sub = 0 未创建子酒店
     * @return
     */
    @Override
    public Result<Object> queryOneNotDealByNotifyOrderId() {
        SwitchOrderListNotify switchOrderListNotify =  switchOrderListNotifyMapper.queryOneNotDealByNotifyOrderId();

        if(null != switchOrderListNotify){
            /*
            version 20200903 qyy  该需求暂时不需要if("100".equals(switchOrderListNotify.getOrderStatus())){
                return new Result<>("fai1_"+switchOrderListNotify.getMd5Key(),"error");//c不处理
            }
            Date createTime = switchOrderListNotify.getCreateTime();//过去
            Long difMin = DateUtil.dateDiff(DateUtil.formatDate(createTime,"yyyy-MM-dd HH:mm:ss"),"min","2020-08-13 18:45:30","yyyy-MM-dd HH:mm:ss");
            if(30<=difMin){
                return new Result<>("fai2"+switchOrderListNotify.getMd5Key(),"error");//超过半小时未处理成功的通知单不再处理
            }*/
            return new Result<>(switchOrderListNotify.getMd5Key(),"success");
        }
        return new Result<>(null,"success");

    }

    public static void main(String[] args) {
        Date createTime = new Date();//过去时间
        Long difMin = DateUtil.dateDiff(DateUtil.formatDate(createTime,"yyyy-MM-dd HH:mm:ss"),"min","2020-08-13 18:45:30","yyyy-MM-dd HH:mm:ss");
        if(30<=difMin){
            System.out.printf("30303===="+difMin);
        }else{
            System.out.printf("1111===="+difMin);
        }
    }
    @Override
    public Result<Object> updateNotifyOrderIsDeal(String id, Integer isDeal,String isDealRemark) {
        Map map = new HashMap();
        map.put("md5Key",id);
        map.put("isDeal",isDeal);
        map.put("isDealRemark",isDealRemark);
        /*if(2 == isDeal){
            //失败 增加过滤N新增
            map.put("formType","N");
        }*/
        switchOrderListNotifyMapper.updateNotifyOrderIsDeal(map);
        return new Result<>();
    }


}
